package textrpg.guihandlers;

import textrpg.player.skills.Mining;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import textrpg.Loader;

public class MiningGui {

    public JButton mineCopperButton;
    public JButton mineIronButton;
    public JButton mineMithrilButton;
    public JButton mineAdamantiteButton;
    public JButton mineRuneButton;
    Mining mine = new Mining();

    public MiningGui() throws IOException {
        mineCopperButton = new JButton("Mine Copper");
        mineIronButton = new JButton("Mine Iron");
        mineMithrilButton = new JButton("Mine Mithril");
        mineAdamantiteButton = new JButton("Mine Adamantite");
        mineRuneButton = new JButton("Mine Rune");

        mineCopperButton.setPreferredSize(new Dimension(40, 40));
        mineIronButton.setPreferredSize(new Dimension(40, 40));
        mineMithrilButton.setPreferredSize(new Dimension(40, 40));
        mineAdamantiteButton.setPreferredSize(new Dimension(40, 40));
        mineRuneButton.setPreferredSize(new Dimension(40, 40));

        mineCopperButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        mineIronButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        mineMithrilButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        mineAdamantiteButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        mineRuneButton.setAlignmentX(Component.CENTER_ALIGNMENT);

        mineCopperButton.addActionListener(new MineCopperListener());
        mineIronButton.addActionListener(new MineIronListener());
        mineMithrilButton.addActionListener(new MineMithrilListener());
        mineAdamantiteButton.addActionListener(new MineAdamantiteListener());
        mineRuneButton.addActionListener(new MineRuneListener());
    }

    private class MineCopperListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent ae) {
            mine.mineRock(0, 10);
            GuiCoreInitializer.consoleDisplay.append(Loader.updateConsole());
            GuiCoreInitializer.consoleDisplay.setCaretPosition(GuiCoreInitializer.consoleDisplay.getDocument().getLength());

        }
    }

    private class MineIronListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent ae) {
            mine.mineRock(1, 10);
            GuiCoreInitializer.consoleDisplay.append(Loader.updateConsole());
            GuiCoreInitializer.consoleDisplay.setCaretPosition(GuiCoreInitializer.consoleDisplay.getDocument().getLength());
        }
    }

    private class MineMithrilListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent ae) {

            mine.mineRock(2, 10);
            GuiCoreInitializer.consoleDisplay.append(Loader.updateConsole());
            GuiCoreInitializer.consoleDisplay.setCaretPosition(GuiCoreInitializer.consoleDisplay.getDocument().getLength());
        }
    }

    private class MineAdamantiteListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent ae) {
            mine.mineRock(3, 10);
            GuiCoreInitializer.consoleDisplay.append(Loader.updateConsole());
            GuiCoreInitializer.consoleDisplay.setCaretPosition(GuiCoreInitializer.consoleDisplay.getDocument().getLength());
        }
    }

    private class MineRuneListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent ae) {
            mine.mineRock(4, 10);
            GuiCoreInitializer.consoleDisplay.append(Loader.updateConsole());
            GuiCoreInitializer.consoleDisplay.setCaretPosition(GuiCoreInitializer.consoleDisplay.getDocument().getLength());
        }
    }
}
